package com.jwgf.smarowindingmachine_unity.ui;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.fragment.app.DialogFragment;

import com.jwgf.adapter.CommonAdapter;
import com.jwgf.adapter.ViewHolder;
import com.jwgf.common.AppContext;
import com.jwgf.common.ViewCache;
import com.jwgf.objectbox.HeadFaultRecord;
import com.jwgf.objectbox.HeadFaultRecord_;
import com.jwgf.objectbox.ObjectBox;
import com.jwgf.objectbox.ProcessRecord;
import com.jwgf.objectbox.ProcessRecord_;
import com.jwgf.objectbox.RedLightRecord;
import com.jwgf.objectbox.RedLightRecord_;
import com.jwgf.objectbox.ShiftReport;
import com.jwgf.objectbox.ShiftReport_;
import com.jwgf.objectbox.UserLogin;
import com.jwgf.smarowindingmachine_unity.R;
import com.jwgf.smarowindingmachine_unity.logic.Report;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

import io.objectbox.Box;
import io.objectbox.query.QueryBuilder;

public class ProductionManagementStatisticsReportFragment extends BaseFragment implements OnClickListener {

    private View v;
    private LinearLayout startDateLv;
    private LinearLayout endDateLv;
    private TextView tvStartDate;
    private TextView tvEndDate;
    long startTimes = 0;
    long endTimes = 0;
    private Spinner operator_spinner;
    private Spinner shift_team_spinner;
    private Button btnQuery;

    private ArrayList<String> shiftTeamList = new ArrayList<String>();
    private ArrayAdapter<String> operatorAdapter;
    private ArrayList<String> operatorList = new ArrayList<String>();
    private ArrayAdapter<String> shiftNumAdapter;
    private ArrayList<String> shiftNumList = new ArrayList<String>();
    private String strShiftTeam;
    private String strOperateNum;

    private ListView lvProduction;
    private CommonAdapter productionAdapter;
    private List<HashMap<String, String>> productionList = new ArrayList<HashMap<String, String>>();
    private static final String START_TIME = "start_time";
    private static final String END_TIME = "end_time";

    // fault coloum
    private static final String COLOUM_1 = "content";
    private static final String COLOUM_2 = "class_1";
    private static final String COLOUM_3 = "class_2";
    private static final String COLOUM_4 = "class_3";
    private static final String COLOUM_5 = "class_4";
    private static final String COLOUM_6 = "class_total";
    // fault row
    public static final String ROW_1 = "total_winding_time";// 落纱时间
    public static final String ROW_2 = "total_number_cops_changed";// 更换管纱数
    public static final String ROW_3 = "total_yarn_joints";// 接头数
    public static final String ROW_4 = "total_yarn_joints_div10";
    public static final String ROW_5 = "total_yarn_joints_div_package";
    public static final String ROW_6 = "total_number_cut_of_faults";// 切疵次数
    public static final String ROW_7 = "total_number_cut_of_faults_div10";
    public static final String ROW_8 = "total_number_cut_of_faults_div_cop";
    public static final String ROW_9 = "total_number_cut_of_faults_div_package";
    public static final String ROW_10 = "total_number_doffed_package";// 生产筒纱数
    public static final String ROW_11 = "total_succeeded_spindle_doffer_number";// 小车络桶成功个数
    public static final String ROW_12 = "total_splice_cycles";// 粘接循环次数
    public static final String ROW_13 = "total_spindle_production";// 单钉产量
    public static final String ROW_14 = "total_spindle_production_efficiency";// 单钉生产效率
    public static final String ROW_15 = "total_spindle_mechanical_efficiency";// 单钉机械效率
    public static final String[] ROW = {ROW_1, ROW_2, ROW_3, ROW_4, ROW_5, ROW_6, ROW_7, ROW_8, ROW_9, ROW_10, ROW_11,
            ROW_12, ROW_13, ROW_14, ROW_15};
    public static final String[] COL_CONTENT = AppContext.getInstance().getResources()
            .getStringArray(R.array.statics_pro_data);

    // 故障
    private Button btQueryFaultInfo;
    private TextView tvFaultCounts;
    private TextView tvFaultElapse;
    private static final String FAULT_COUNT = "fault_count";
    private static final String FAULT_ELAPSE = "fault_elapse";

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initViews();
    }

    private void initViews() {
        startDateLv = (LinearLayout) v.findViewById(R.id.pm_statistics_reported_start_date_lv);
        endDateLv = (LinearLayout) v.findViewById(R.id.pm_statistics_reported_end_date_lv);
        startDateLv.setOnClickListener(this);
        endDateLv.setOnClickListener(this);
        tvStartDate = (TextView) v.findViewById(R.id.pm_statistics_reported_start_date_value);
        tvEndDate = (TextView) v.findViewById(R.id.pm_statistics_reported_end_date_value);

        Calendar nowCal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        tvStartDate.setText(sdf.format(nowCal.getTime()));
        tvEndDate.setText(sdf.format(nowCal.getTime()));

        btnQuery = (Button) v.findViewById(R.id.pm_statistics_reported_query_btn);
        btnQuery.setOnClickListener(this);

        operator_spinner = (Spinner) v.findViewById(R.id.pm_statistics_reported_employeenum_spinner);
        shift_team_spinner = (Spinner) v.findViewById(R.id.pm_statistics_reported_shiftteam_spinner);

        shiftNumList.clear();
        String[] shiftNums = getActivity().getResources().getStringArray(R.array.shift);
        for (int i = 0; i < shiftNums.length; i++) {
            shiftNumList.add(shiftNums[i]);
        }

        shiftTeamList.clear();
        String[] shiftTeams = getActivity().getResources().getStringArray(R.array.shift_team_in_statics);
        for (int i = 0; i < shiftTeams.length; i++) {
            shiftTeamList.add(shiftTeams[i]);
        }
        shift_team_spinner.setAdapter(new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_dropdown_item_1line, shiftTeamList));
        strShiftTeam = shiftTeamList.get(0);// 默认为第一个班组
        shift_team_spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
                strShiftTeam = shiftTeamList.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }
        });

        operator_spinner.setAdapter(operatorAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_dropdown_item_1line, getOperatorData()));
        strOperateNum = operatorList.get(0);// 默认为第一个员工号
        operator_spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                strOperateNum = operatorList.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        productionList.clear();
        lvProduction = (ListView) v.findViewById(R.id.production_list);
        // lvProduction.setOnItemClickListener(this);
        lvProduction.setAdapter(productionAdapter = new CommonAdapter<HashMap<String, String>>(getActivity(),
                productionList, R.layout.item_production_list) {

            @Override
            public void convert(ViewHolder holder, HashMap<String, String> item) {
                holder.setText(R.id.production_fault_column1, item.get(COLOUM_1));
                holder.setText(R.id.production_fault_column2, item.get(COLOUM_2));
                holder.setText(R.id.production_fault_column3, item.get(COLOUM_3));
                holder.setText(R.id.production_fault_column4, item.get(COLOUM_4));
                holder.setText(R.id.production_fault_column5, item.get(COLOUM_5));
                holder.setText(R.id.production_fault_column6, item.get(COLOUM_6));
            }
        });

        tvFaultCounts = (TextView) v.findViewById(R.id.statistics_fault_info_fault_count_value);
        tvFaultElapse = (TextView) v.findViewById(R.id.statistics_fault_info_fault_elapse_value);
        btQueryFaultInfo = (Button) v.findViewById(R.id.statistics_fault_info_query_btn);
        btQueryFaultInfo.setOnClickListener(this);
        updateViews();
    }

    private void updateViews() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        try {
            startTimes = sdf.parse(tvStartDate.getText().toString()).getTime();
            endTimes = sdf.parse(tvEndDate.getText().toString()).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        endTimes += (24 * 3600 - 1) * 1000;// 取出的时间为*月*日0点时间，结束时间以24点为准进行查询
        getProductionData(startTimes, endTimes);
        productionAdapter.notifyDataSetChanged();
        updateFaultInfo(startTimes, endTimes);
    }

    private void updateFaultInfo(long startTimes, long endTimes) {
        List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
        int count = 0;
        long elapse = 0;


        ArrayList<HashMap<String, String>> dataList = new ArrayList<>();
        Box<RedLightRecord> redLightBox = ObjectBox.get().boxFor(RedLightRecord.class);
        long redCount = redLightBox.query().between(RedLightRecord_.start, startTimes, endTimes).build().count();
        long redTime = redLightBox.query().between(RedLightRecord_.start, startTimes, endTimes).build().property(RedLightRecord_.duration).sum();
        HashMap<String, String> item = new HashMap<String, String>();
        item.put(FAULT_COUNT, String.valueOf(redCount));
        item.put(FAULT_ELAPSE, String.valueOf(redTime));
        dataList.add(item);

        Box<ProcessRecord> processBox = ObjectBox.get().boxFor(ProcessRecord.class);
        long processCount = processBox.query().between(ProcessRecord_.start, startTimes, endTimes).build().count();
        long processTime = processBox.query().between(ProcessRecord_.start, startTimes, endTimes).build().property(ProcessRecord_.duration).sum();

        item = new HashMap<String, String>();
        item.put(FAULT_COUNT, String.valueOf(processCount));
        item.put(FAULT_ELAPSE, String.valueOf(processTime));
        dataList.add(item);

        Box<HeadFaultRecord> plcFaultBox = ObjectBox.get().boxFor(HeadFaultRecord.class);
        long plcFaultCount = plcFaultBox.query().between(HeadFaultRecord_.start, startTimes, endTimes).build().count();
        long plcFaultTime = plcFaultBox.query().between(HeadFaultRecord_.start, startTimes, endTimes).build().property(HeadFaultRecord_.duration).sum();

        item = new HashMap<String, String>();
        item.put(FAULT_COUNT, String.valueOf(plcFaultCount));
        item.put(FAULT_ELAPSE, String.valueOf(plcFaultTime));
        dataList.add(item);

        list.addAll(dataList);
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).get(FAULT_COUNT).equals("0")) {
                continue;
            }
            count += Integer.valueOf(list.get(i).get(FAULT_COUNT));
            elapse += Long.valueOf(list.get(i).get(FAULT_ELAPSE));
        }
        tvFaultCounts.setText(String.valueOf(count));
        tvFaultElapse.setText(Report.getInstance().subSecToTime(elapse / 1000));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        v = ViewCache.getInstance().getView(R.layout.fragment_production_management_statistics_report);
        return v;
    }

    private List<String> getOperatorData() {
        operatorList.clear();
        Box<UserLogin> box = ObjectBox.get().boxFor(UserLogin.class);
        List<UserLogin> list = box.getAll();
        for (UserLogin user : list) {
            operatorList.add(user.user);
        }
        operatorList.add(operatorList.size(), getResources().getString(R.string.all));
        return operatorList;
    }

    private List<HashMap<String, String>> getProductionData(long start, long end) {
        Box<ShiftReport> box = ObjectBox.get().boxFor(ShiftReport.class);
        QueryBuilder<ShiftReport> queryBuilder = box.query()
                .between(ShiftReport_.start, start, end).equal(ShiftReport_.type, getString(R.string.sum));

        if (!(strShiftTeam.equals(getActivity().getString(R.string.all)))) {
            queryBuilder = queryBuilder.equal(ShiftReport_.team, strShiftTeam).order(ShiftReport_.shiftNum);
        }
        if (!(strOperateNum.equals(getActivity().getString(R.string.all)))) {
            queryBuilder = queryBuilder.equal(ShiftReport_.operator, strOperateNum).order(ShiftReport_.shiftNum);
        }

        List<ShiftReport> list = queryBuilder.build().find();
        ShiftReport[] sumReport = new ShiftReport[4];
        for (int i = 0; i < 4; ++i) {
            sumReport[i] = new ShiftReport();
        }

        for (ShiftReport report : list) {
            int index = report.shiftNum - 1;
            sumReport[index].windingTime += report.windingTime;
            sumReport[index].copChangeCount += report.copChangeCount;
            sumReport[index].yarnJointCount += report.yarnJointCount;
            sumReport[index].yarnJointCountPer10Km += report.yarnJointCountPer10Km;
            sumReport[index].yarnJointCountPerPackage += report.yarnJointCountPerPackage;
            sumReport[index].cutCount += report.cutCount;
            sumReport[index].cutCountPer10Km += report.cutCountPer10Km;
            sumReport[index].cutCountPerCop += report.cutCountPerCop;
            sumReport[index].cutCountPerPackage += report.cutCountPerPackage;
            sumReport[index].packageCount += report.packageCount;
            sumReport[index].succeedDoffingPackageCount += report.succeedDoffingPackageCount;
            sumReport[index].spliceCount += report.spliceCount;
            sumReport[index].production += report.production;
            sumReport[index].runEfficiency += report.runEfficiency;
            sumReport[index].mechanicalEfficiency += report.mechanicalEfficiency;
        }
        productionList.clear();

        for (int i = 0; i < ROW.length; i++) {
            HashMap<String, String> item = new HashMap<String, String>();
            item.put(COLOUM_1, COL_CONTENT[i]);
            if (0 == i) {
                item.put(COLOUM_2, Report.getInstance().subSecToTime(sumReport[0].windingTime / 1000));
                item.put(COLOUM_3, Report.getInstance().subSecToTime(sumReport[1].windingTime / 1000));
                item.put(COLOUM_4, Report.getInstance().subSecToTime(sumReport[2].windingTime / 1000));
                item.put(COLOUM_5, Report.getInstance().subSecToTime(sumReport[3].windingTime / 1000));
                item.put(COLOUM_6, Report.getInstance().subSecToTime((sumReport[0].windingTime + sumReport[1].windingTime
                        + sumReport[2].windingTime + sumReport[3].windingTime) / 1000));
            } else if (i == 1) {
                item.put(COLOUM_2, String.valueOf(sumReport[0].copChangeCount));
                item.put(COLOUM_3, String.valueOf(sumReport[1].copChangeCount));
                item.put(COLOUM_4, String.valueOf(sumReport[2].copChangeCount));
                item.put(COLOUM_5, String.valueOf(sumReport[3].copChangeCount));
                item.put(COLOUM_6, String.valueOf(sumReport[0].copChangeCount + sumReport[1].copChangeCount
                        + sumReport[2].copChangeCount + sumReport[3].copChangeCount));
            } else if (i == 2) {
                item.put(COLOUM_2, String.valueOf(sumReport[0].yarnJointCount));
                item.put(COLOUM_3, String.valueOf(sumReport[1].yarnJointCount));
                item.put(COLOUM_4, String.valueOf(sumReport[2].yarnJointCount));
                item.put(COLOUM_5, String.valueOf(sumReport[3].yarnJointCount));
                item.put(COLOUM_6, String.valueOf(sumReport[0].yarnJointCount + sumReport[1].yarnJointCount
                        + sumReport[2].yarnJointCount + sumReport[3].yarnJointCount));
            } else if (i == 3) {
                item.put(COLOUM_2, String.valueOf(Report.getInstance().reFloat(sumReport[0].yarnJointCountPer10Km)));
                item.put(COLOUM_3, String.valueOf(Report.getInstance().reFloat(sumReport[1].yarnJointCountPer10Km)));
                item.put(COLOUM_4, String.valueOf(Report.getInstance().reFloat(sumReport[2].yarnJointCountPer10Km)));
                item.put(COLOUM_5, String.valueOf(Report.getInstance().reFloat(sumReport[3].yarnJointCountPer10Km)));
                item.put(COLOUM_6, String.valueOf(Report.getInstance().reFloat(sumReport[0].yarnJointCountPer10Km
                        + sumReport[1].yarnJointCountPer10Km + sumReport[2].yarnJointCountPer10Km
                        + sumReport[3].yarnJointCountPer10Km)));
            } else if (i == 4) {
                item.put(COLOUM_2, String.valueOf(Report.getInstance().reFloat(sumReport[0].yarnJointCountPerPackage)));
                item.put(COLOUM_3, String.valueOf(Report.getInstance().reFloat(sumReport[1].yarnJointCountPerPackage)));
                item.put(COLOUM_4, String.valueOf(Report.getInstance().reFloat(sumReport[2].yarnJointCountPerPackage)));
                item.put(COLOUM_5, String.valueOf(Report.getInstance().reFloat(sumReport[3].yarnJointCountPerPackage)));
                item.put(COLOUM_6, String.valueOf(Report.getInstance().reFloat(sumReport[0].yarnJointCountPerPackage
                        + sumReport[1].yarnJointCountPerPackage + sumReport[2].yarnJointCountPerPackage
                        + sumReport[3].yarnJointCountPerPackage)));
            } else if (i == 5) {
                item.put(COLOUM_2, String.valueOf(sumReport[0].cutCount));
                item.put(COLOUM_3, String.valueOf(sumReport[1].cutCount));
                item.put(COLOUM_4, String.valueOf(sumReport[2].cutCount));
                item.put(COLOUM_5, String.valueOf(sumReport[3].cutCount));
                item.put(COLOUM_6, String.valueOf(sumReport[0].cutCount + sumReport[1].cutCount
                        + sumReport[2].cutCount + sumReport[3].cutCount));
            } else if (i == 6) {
                item.put(COLOUM_2, String.valueOf(Report.getInstance().reFloat(sumReport[0].cutCountPer10Km)));
                item.put(COLOUM_3, String.valueOf(Report.getInstance().reFloat(sumReport[1].cutCountPer10Km)));
                item.put(COLOUM_4, String.valueOf(Report.getInstance().reFloat(sumReport[2].cutCountPer10Km)));
                item.put(COLOUM_5, String.valueOf(Report.getInstance().reFloat(sumReport[3].cutCountPer10Km)));
                item.put(COLOUM_6, String.valueOf(Report.getInstance().reFloat(sumReport[0].cutCountPer10Km
                        + sumReport[1].cutCountPer10Km + sumReport[2].cutCountPer10Km
                        + sumReport[3].cutCountPer10Km)));
            } else if (i == 7) {
                item.put(COLOUM_2, String.valueOf(Report.getInstance().reFloat(sumReport[0].cutCountPerCop)));
                item.put(COLOUM_3, String.valueOf(Report.getInstance().reFloat(sumReport[1].cutCountPerCop)));
                item.put(COLOUM_4, String.valueOf(Report.getInstance().reFloat(sumReport[2].cutCountPerCop)));
                item.put(COLOUM_5, String.valueOf(Report.getInstance().reFloat(sumReport[3].cutCountPerCop)));
                item.put(COLOUM_6, String.valueOf(Report.getInstance().reFloat(sumReport[0].cutCountPerCop
                        + sumReport[1].cutCountPerCop + sumReport[2].cutCountPerCop
                        + sumReport[3].cutCountPerCop)));
            } else if (i == 8) {
                item.put(COLOUM_2, String.valueOf(Report.getInstance().reFloat(sumReport[0].cutCountPerPackage)));
                item.put(COLOUM_3, String.valueOf(Report.getInstance().reFloat(sumReport[1].cutCountPerPackage)));
                item.put(COLOUM_4, String.valueOf(Report.getInstance().reFloat(sumReport[2].cutCountPerPackage)));
                item.put(COLOUM_5, String.valueOf(Report.getInstance().reFloat(sumReport[3].cutCountPerPackage)));
                item.put(COLOUM_6, String.valueOf(Report.getInstance().reFloat(sumReport[0].cutCountPerPackage
                        + sumReport[1].cutCountPerPackage + sumReport[2].cutCountPerPackage
                        + sumReport[3].cutCountPerPackage)));
            } else if (i == 9) {
                item.put(COLOUM_2, String.valueOf(sumReport[0].packageCount));
                item.put(COLOUM_3, String.valueOf(sumReport[1].packageCount));
                item.put(COLOUM_4, String.valueOf(sumReport[2].packageCount));
                item.put(COLOUM_5, String.valueOf(sumReport[3].packageCount));
                item.put(COLOUM_6, String.valueOf(sumReport[0].packageCount + sumReport[1].packageCount
                        + sumReport[2].packageCount + sumReport[3].packageCount));
            } else if (i == 10) {
                item.put(COLOUM_2, String.valueOf(sumReport[0].succeedDoffingPackageCount));
                item.put(COLOUM_3, String.valueOf(sumReport[1].succeedDoffingPackageCount));
                item.put(COLOUM_4, String.valueOf(sumReport[2].succeedDoffingPackageCount));
                item.put(COLOUM_5, String.valueOf(sumReport[3].succeedDoffingPackageCount));
                item.put(COLOUM_6, String.valueOf(sumReport[0].succeedDoffingPackageCount + sumReport[1].succeedDoffingPackageCount
                        + sumReport[2].succeedDoffingPackageCount + sumReport[3].succeedDoffingPackageCount));
            } else if (11 == i) {//正数显示
                item.put(COLOUM_2, String.valueOf(sumReport[0].spliceCount));
                item.put(COLOUM_3, String.valueOf(sumReport[1].spliceCount));
                item.put(COLOUM_4, String.valueOf(sumReport[2].spliceCount));
                item.put(COLOUM_5, String.valueOf(sumReport[3].spliceCount));
                item.put(COLOUM_6, String.valueOf(sumReport[0].spliceCount + sumReport[1].spliceCount
                        + sumReport[2].spliceCount + sumReport[3].spliceCount));
            } else if (i == 12) {
                item.put(COLOUM_2, String.valueOf(Report.getInstance().reFloat(sumReport[0].production)));
                item.put(COLOUM_3, String.valueOf(Report.getInstance().reFloat(sumReport[1].production)));
                item.put(COLOUM_4, String.valueOf(Report.getInstance().reFloat(sumReport[2].production)));
                item.put(COLOUM_5, String.valueOf(Report.getInstance().reFloat(sumReport[3].production)));
                item.put(COLOUM_6, String.valueOf(Report.getInstance().reFloat(sumReport[0].production
                        + sumReport[1].production + sumReport[2].production
                        + sumReport[3].production)));
            } else if (i == 13) {
                item.put(COLOUM_2, String.valueOf(Report.getInstance().reFloat(sumReport[0].runEfficiency)));
                item.put(COLOUM_3, String.valueOf(Report.getInstance().reFloat(sumReport[1].runEfficiency)));
                item.put(COLOUM_4, String.valueOf(Report.getInstance().reFloat(sumReport[2].runEfficiency)));
                item.put(COLOUM_5, String.valueOf(Report.getInstance().reFloat(sumReport[3].runEfficiency)));
                item.put(COLOUM_6, String.valueOf(Report.getInstance().reFloat(sumReport[0].runEfficiency
                        + sumReport[1].runEfficiency + sumReport[2].runEfficiency
                        + sumReport[3].runEfficiency)));
            } else {
                item.put(COLOUM_2, String.valueOf(Report.getInstance().reFloat(sumReport[0].mechanicalEfficiency)));
                item.put(COLOUM_3, String.valueOf(Report.getInstance().reFloat(sumReport[1].mechanicalEfficiency)));
                item.put(COLOUM_4, String.valueOf(Report.getInstance().reFloat(sumReport[2].mechanicalEfficiency)));
                item.put(COLOUM_5, String.valueOf(Report.getInstance().reFloat(sumReport[3].mechanicalEfficiency)));
                item.put(COLOUM_6, String.valueOf(Report.getInstance().reFloat(sumReport[0].mechanicalEfficiency
                        + sumReport[1].mechanicalEfficiency + sumReport[2].mechanicalEfficiency
                        + sumReport[3].mechanicalEfficiency)));
            }

            productionList.add(item);
        }

        return productionList;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.pm_statistics_reported_start_date_lv:
                Calendar startCal = Calendar.getInstance();
                new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {

                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        tvStartDate.setText(new StringBuilder().append(year)
                                .append((monthOfYear + 1) < 10 ? "0" + (monthOfYear + 1) : (monthOfYear + 1))
                                .append((dayOfMonth < 10) ? "0" + dayOfMonth : dayOfMonth));
                    }
                }, startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH), startCal.get(Calendar.DAY_OF_MONTH)).show();

                break;
            case R.id.pm_statistics_reported_end_date_lv:
                Calendar endCal = Calendar.getInstance();
                new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {

                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        tvEndDate.setText(new StringBuilder().append(year)
                                .append((monthOfYear + 1) < 10 ? "0" + (monthOfYear + 1) : (monthOfYear + 1))
                                .append((dayOfMonth < 10) ? "0" + dayOfMonth : dayOfMonth));
                    }
                }, endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH), endCal.get(Calendar.DAY_OF_MONTH)).show();
                break;
            case R.id.pm_statistics_reported_query_btn:
                updateViews();
                break;
            case R.id.statistics_fault_info_query_btn:
                DialogFragment dlg = new FaultDetailDiaInStatisticsReport();
                Bundle args = new Bundle();
                args.putLong(START_TIME, startTimes);
                args.putLong(END_TIME, endTimes);
                dlg.setArguments(args);
                dlg.show(getFragmentManager(), "fault_detail_shift_report");

                break;
            default:
                break;
        }
    }

}
